﻿var dragapproved = false;
var minrestore = 0;  //该变量表示窗口目前的状态，0表示初始化状态，1表示最大化状态
var initialwidth, initialheight, windowname;
//若Client浏览器为IE5.0以上版本的
var ie5 = document.all && document.getElementById;
//若Client浏览器为NetsCape6。0版本以上的
var ns6 = document.getElementById && !document.all;
top.coverDivReturnValue = 0;
top.callBackHandler = null;
//遮罩层
var IFrame = {			//去掉此函数，无遮罩效果
    createIframe: function () {
        var div = document.createElement("<div id='iframeDiv' style='filter:alpha(opacity=50)'></div>");
        var divFront = document.createElement("<div></div>");
        var iframe = document.createElement("<iframe frameborder='0'></iframe>");

        div.appendChild(divFront);
        div.appendChild(iframe);
        document.body.appendChild(div);
        //top.document.body.appendChild(div);
        
        div.style.height = document.body.offsetHeight;
        div.style.width = document.body.offsetWidth;
        div.style.position = "absolute";
        div.style.zIndex = 1998;
        div.style.left = 0;
        div.style.top = 0;

        divFront.style.height = document.body.offsetHeight;
        divFront.style.width = document.body.offsetWidth;
        divFront.style.position = "absolute";
        divFront.style.background = "black";
        divFront.style.zIndex = 1999;
        divFront.style.left = 0;
        divFront.style.top = 0;

        iframe.style.height = document.body.offsetHeight;
        iframe.style.width = document.body.offsetWidth;
        iframe.style.position = "absolute";
        iframe.style.zIndex = -1;
        iframe.style.left = 0;
        iframe.style.top = 0;
        /*
        var _H = top.document.body.offsetHeight;
        var _W = top.document.body.offsetWidth;
        var _top = document.body.offsetHeight - top.document.body.offsetHeight;
        var _left = document.body.offsetWidth - top.document.body.offsetWidth;
        alert("h:" + _H + " w:" + _W + " top:" + _top + " left:" + _left);
        div.style.height = _H;
        div.style.width = _W;
        div.style.position = "absolute";
        div.style.zIndex = 1998;
        div.style.left = _left;
        div.style.top = _top;

        divFront.style.height = document.body.offsetHeight;
        divFront.style.width = document.body.offsetWidth;
        divFront.style.position = "absolute";
        divFront.style.background = "black";
        divFront.style.zIndex = 1999;
        divFront.style.left = _left;
        divFront.style.top = _top;

        iframe.style.height = _H;
        iframe.style.width = _W;
        iframe.style.position = "absolute";
        iframe.style.zIndex = -1;
        iframe.style.left = _left;
        iframe.style.top = _top; */

    },
    closeIframe: function () {
        var iframeDiv = document.getElementById("iframeDiv");
        document.body.removeChild(iframeDiv);
        //  top.document.body.removeChild(iframeDiv);
    }
}
function iecompattest() {
    return (!window.opera && document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body;
}
function drag_drop(e) {
    if (ie5 && dragapproved && event.button == 1) {
        document.getElementById("dwindow").style.left = tempx + event.clientX - offsetx;
        document.getElementById("dwindow").style.top = tempy + event.clientY - offsety;
    } else if (ns6 && dragapproved) {
        document.getElementById("dwindow").style.left = tempx + e.clientX - offsetx;
        document.getElementById("dwindow").style.top = tempy + e.clientY - offsety;
    }
}
function initializedrag(e) {
    offsetx = ie5 ? event.clientX : e.clientX;
    offsety = ie5 ? event.clientY : e.clientY;
    //document.getElementById("dwindowcontent").style.display="none"; //此句代码可不要
    tempx = parseInt(document.getElementById("dwindow").style.left);
    tempy = parseInt(document.getElementById("dwindow").style.top);

    dragapproved = true
    document.getElementById("dwindow").onmousemove = drag_drop
}

function loadwindow(url, width, height, name, callhandler) {   
    if (callhandler) {
        top.callBackHandler =callhandler;
        //alert(typeof (callhandler));
    }
    if (!ie5 && !ns6)  //若不为IE或Netscpae浏览器，则使用一般的Window.open进行弹出窗口处理
        window.open(url, "", "width=width,height=height,scrollbars=1");
    else {
        IFrame.createIframe();   ////去掉此函数，无遮罩效果
        document.getElementById("dwindow").style.display = '';

        initialwidth = width;
        initialheight = height;
        windowname = name;

        document.getElementById("dwindow").style.width = initialwidth;
        document.getElementById("dwindow").style.height = initialheight;
        document.getElementById("dwindow").style.left = (document.body.offsetWidth / 2) - (initialwidth / 2);
        document.getElementById("dwindow").style.top = (document.body.offsetHeight / 2) - (initialheight / 2);
        document.getElementById("cframe").src = url;
        document.getElementById("windowname").innerHTML = windowname; //lable的innerHTML
    }

}
function maximize() {
    if (minrestore == 0) {
        minrestore = 1; //maximize window
        document.getElementById("maxname").setAttribute("src", "/image/proj/min.gif");
        document.getElementById("dwindow").style.width = ns6 ? window.innerWidth - 20 : iecompattest().clientWidth;
        document.getElementById("dwindow").style.height = ns6 ? window.innerHeight - 20 : iecompattest().clientHeight;

        document.getElementById("dwindow").style.left = ns6 ? window.pageXOffset : iecompattest().scrollLeft
        document.getElementById("dwindow").style.top = ns6 ? window.pageYOffset : iecompattest().scrollTop
    } else {
        minrestore = 0; //restore window
        document.getElementById("maxname").setAttribute("src", "/image/proj/max.gif");

        document.getElementById("dwindow").style.width = initialwidth;
        document.getElementById("dwindow").style.height = initialheight;

        document.getElementById("dwindow").style.left = (document.body.offsetWidth / 2) - (initialwidth / 2);
        document.getElementById("dwindow").style.top = (document.body.offsetHeight / 2) - (initialheight / 2);
    }
    document.getElementById("windowname").value = windowname;
}

function closeit() {
    document.getElementById("dwindow").style.display = "none";
    IFrame.closeIframe(); //去掉此函数，无遮罩效果
}
function stopdrag() {
    dragapproved = false;
}
